package com.bwie.controller;

import com.bwie.pojo.TbProd;
import com.bwie.service.TbProdService;
import com.bwie.utils.Result;
import com.bwie.vo.AttaVo;
import com.bwie.vo.ProdPageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/shop/index")
public class TbProdController {
    @Autowired
    TbProdService tbProdService;

    /**
     * 获取商品列表
     * @return
     */
    @PostMapping("/getProdList")
    public Result getProdList(@RequestBody ProdPageVo prodPageVo){
        return tbProdService.getProdList(prodPageVo);
    }

    /**
     * 添加商品
     * @param tbProd
     * @return
     */
    @PostMapping("/addProd")
    public Result addProd(@RequestBody @Validated TbProd tbProd){
        return tbProdService.addProd(tbProd);
    }

    /**
     * 批量删除商品
     * @param prodList
     * @return
     */
    @PostMapping("/deleteProdAll")
    public Result deleteProdAll(@RequestBody List<TbProd> prodList){
        return tbProdService.deleteProdAll(prodList);
    }

    /**
     * 添加商品附件
     * @return
     */
    @PostMapping("/addProdAtta")
    public Result addProdAtta(@RequestBody AttaVo attaVo){
        return tbProdService.addProdAtta(attaVo);
    }

    @PostMapping("/checkProd")
    public Result checkProd(@RequestBody TbProd tbProd){
        return tbProdService.checkProd(tbProd);
    }

    /**
     * 从ES中获取商品分页列表
     * @param prodPageVo
     * @return
     */
    @PostMapping("/getProdListFromEs")
    public Result getProdListFromEs(@RequestBody ProdPageVo prodPageVo){
        return tbProdService.getProdListFromEs(prodPageVo);
    }

}
